<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <link rel="stylesheet" href="../../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <input type="text" id="authorityId" name="authorityId" style="display: none">
        <label class="layui-form-label required">目录/菜单/按钮名</label>
        <div class="layui-input-block">
            <input type="text" id="authorityName" name="authorityName" lay-verify="required"
                   lay-reqtext="请输入目录/菜单/按钮名" placeholder="请输入目录/菜单/按钮" value="" class="layui-input">
            <tip>填写目录/菜单/按钮的名称。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限标识</label>
        <div class="layui-input-block">
            <input type="text" id="authority" name="authority" placeholder="请输入权限标识" value=""
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单url</label>
        <div class="layui-input-block">
            <input type="url" id="menuUrl" name="menuUrl" placeholder="请输入菜单url" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">排序号</label>
        <div class="layui-input-block">
            <input type="number" id="orderNumber" name="orderNumber" lay-verify="required" lay-reqtext="排序号不能为空"
                   placeholder="请输入排序号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">菜单图标</label>
        <div class="layui-input-block">
            <input name="menuIcon" id="menuIcon" value="fa fa-address-book" class="layui-input"
                   placeholder="请输入菜单图标">
        </div>
    </div>

    <div class="layui-form-item layui-form-text" id="menuType">
        <label class="layui-form-label required">类型</label>
        <div class="layui-input-block">
            <input type="radio" name="isMenu" value="0" title="菜单" id="isMenu">
            <input type="radio" name="isMenu" value="1" title="按钮" id="notMenu">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/ajax-common.js" charset="UTF-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'iconPickerFa', 'layer'], function () {
        var form = layui.form,
            layer = layui.layer,
            iconPickerFa = layui.iconPickerFa,
            $ = layui.$;

        const searchParams = new URLSearchParams(window.location.search);
        const icon = searchParams.get('menuIcon');
        const isMenu = searchParams.get("isMenu");
        const parentId = searchParams.get('parentId');
        if (icon) {
            $("#menuIcon").val(icon);
        }
        if (isMenu === 1) {
            $("#notMenu").attr('checked', 'true');
        }
        if (parentId !== -1) {
            $("#isMenu").attr('checked', 'true');
        }
        form.render();

        iconPickerFa.render({
            // 选择器，推荐使用input
            elem: '#menuIcon',
            // fa 图标接口
            url: "/lib/font-awesome-4.7.0/less/variables.less",
            // 是否开启搜索：true/false，默认true
            search: true,
            // 是否开启分页：true/false，默认true
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            click: function (data) {
                console.log(data);
            },
            // 渲染成功后的回调
            success: function (d) {
                // console.log(d);
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {
            //
            //     // 关闭弹出层
            //     layer.close(index);
            //
            //     var iframeIndex = parent.layer.getFrameIndex(window.name);
            //     parent.layer.close(iframeIndex);
            //
            // });

            post("/api/menu/update", data.field, (resp) => {
                console.log(resp);
                layer.msg('更新成功', {icon: 1})
            })

            return false;
        });

    });
</script>
</body>
</html>